#include <bits/stdc++.h>

using namespace std;

int maxTwoEvents(vector<vector<int>>& events);

int main()
{
	vector<vector<int>> events = { { 1, 3, 2 }, { 4, 5, 2 }, { 2, 4, 3 } };
	int res = maxTwoEvents(events);
	cout << res;
	return 0;
}

struct Event {
	int _time;
	bool _kind;
	int _val;
	Event(int time, bool kind, int val)
		: _time(time) , _kind(kind) , _val(val) { }
	bool operator<(const Event& other) const {
		return tie(_time, _kind) < tie(other._time, other._kind);
	}
};

int maxTwoEvents(vector<vector<int>>& events)
{
	vector<Event> evs;
	for (const auto& event : events) {
		evs.emplace_back(event[0], 0, event[2]);
		evs.emplace_back(event[1], 1, event[2]);
	}
	sort(evs.begin(), evs.end());

	int res = 0, bestFirst = 0;
	for (const auto& [time, kind, val] : evs)
		if (kind) {
			if (val > bestFirst)
				bestFirst = val;
		} else
			res = max(res, val + bestFirst);
	return res;
}
